#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename	:  numa_test
# Version	:  1.0
# Date		:  2023/12/05
# Author	:  yaoxiyao
# Email		:  yaoxiyao@kylinos.com.cn 
# History	:     
#              Version 1.0, 2023/12/05
# Function	:  支持基于NUMA的亲和调度
# Out		:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

# 测试主题
Title_Env_LTFLIB="支持基于NUMA的亲和调度"

# 目标文件
NumaFile="numa_cpubind.sh"
NumaChar="1111"

## TODO : 个性化,初始化
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestInit_LTFLIB(){
        cp ${KERNEL_SRC_DIR_KERNEL}/${NumaFile} ${TmpTestDir_LTFLIB}
        CommRetParse_FailDiy_LTFLIB ${ERROR} "复制文件失败${KERNEL_SRC_DIR_KERNEL}/${NumaFile}"
	    return $TPASS
}


## TODO : 清理函数
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestClean_LTFLIB(){
        Debug_LLE "rm -rf ${TmpTestDir_LTFLIB}/${NumaFile}"
	rm -rf ${TmpTestDir_LTFLIB}/${NumaFile}
        return $TPASS
}


## TODO : 测试用例集
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
Testsuite_LTFLIB(){
        testcase_1
        return $TPASS
}


## TODO ： 支持基于NUMA的亲和调度
#
testcase_1(){
        cd ${TmpTestDir_LTFLIB}
        CommRetParse_LTFLIB "成功进入临时目录${TmpTestDir_LTFLIB}"

        chmod 777 ${NumaFile}
        CommRetParse_LTFLIB "成功赋权文件${NumaFile}"
          
        local membind=`numactl --cpubind=0 --membind=0 ./${NumaFile}`
        [ "Z${membind}" == "Z1111" ]
        CommRetParse_LTFLIB "支持基于NUMA的亲和调度"

        local cpu_num=`cat /proc/cpuinfo |grep processor |tail -n 1 |awk '{print $3}'`
        local phybind=`numactl --physcpubind=+0-${cpu_num} ./${NumaFile}`
        [ "Z${phybind}" == "Z1111" ]
        CommRetParse_LTFLIB "支持基于NUMA的亲和调度"
}


#----------------------------------------------#

source "${LIB_LTFLIB}"
Main_LTFLIB $@